// 百度地图API功能
var map = function(e){
	var CSName;				 //各个城市的名字
	var hegeNumber;  		 //合格数量
	var notHegeNumber; 		 //不合格数量
	var eligibility; 		 //合格率
	var total;				 //总数
	var other_num;			 //其他
	
	var a = 0;
	
	var name = e.name;
	
	var countryName = "中国";
	var dataUrl = e.shujuUrl;
	var tongjuUrl = e.tujiUrl;
	var ProvinceName1 ;
	var cityName = e.cityName;
	var districtName = e.districtName;
	var cookie = []; //当点击下一级的时候，把当前级别存入cookie
	var map = new BMap.Map("allmap",{enableMapClick:false}); 
	var zoom = 5; //放大级别 设置成5
	var loocked = e.lv; //到底是第几级别
	var lv = e.lv;	
	
	//判断传入的  是否是空 如果等于空
	if(e.centerAndZoom == null | e.centerAndZoom == "" | typeof(e.centerAndZoom) == "undefined"){
		//肯定是空的
		if(e.sizeZoom == null | e.sizeZoom == "" | typeof(e.sizeZoom) == "undefined"){
			if(e.lv == 1){
				zoom = 5;      //如果等于1，那么放大级别是5，显示中国
			}else if(e.lv == 2){  
				zoom = 7;		//如果等于2，那么放大级别是5，显示省
			}else if(e.lv == 3){
				zoom = 11;		//如果等于3，那么放大级别是5，显示区
			}else if(e.lv == 4){
				zoom = 14;		//如果等于3，那么放大级别是5，显示旗
			}else{  //当传入的值是
				$('#twinkle').text("参数错误");
				twinkle();
				zoom = 5;   //默认显示中国
			}
			map.centerAndZoom(countryName, zoom);  //显示中国
		}else{
			map.centerAndZoom(countryName, e.sizeZoom);  //
		}
		cookie = [countryName]; // 将中国放进cookie
	}else{
		if(e.sizeZoom == null | e.sizeZoom == "" | typeof(e.sizeZoom) == "undefined"){
			if(e.lv == 1){
				zoom = 5;
			}else if(e.lv == 2){
				zoom = 7;
			}else if(e.lv == 3){
				zoom = 11;
			}else if(e.lv == 4){
				zoom = 14;
			}else{
				$('#twinkle').text("参数错误");
				twinkle();
				zoom = 5;
			}
			map.centerAndZoom(e.centerAndZoom, zoom);  
		}else{
			map.centerAndZoom(e.centerAndZoom, e.sizeZoom);  
		}
		if(e.loadshow != null){
			cookie = [e.loadshow];
		}else{
			cookie = [e.loadshow];
		}
	}
	
	map.addControl(new BMap.OverviewMapControl());
	
	//是否禁用滚轮
	if((e.changeZoom == true | e.changeZoom == "true") & (e.changeZoom != "" | e.changeZoom != null)){
		map.enableScrollWheelZoom(); //默认是启用的 
	}
	map.enableContinuousZoom(); 
	var geoc = new BMap.Geocoder();
	if(e.url == null | e.url == "" | e.url == "undefined"){
		var loadshow = getp();
	}else{
	
			if(e.url == "chinaMapShow"){
				var loadshow = getp();
			}else if(e.url == "ProvinceMapShow"){
				getc(e.pName);
				map.centerAndZoom(e.pName, 7);  //显示省下的所有市
				cookie.push(e.pName);//把当前省的级别方式cookie
			}else if(e.url == "CityMapShow"){
				getq(e.cName,e.pName);
				lv=3;
				map.centerAndZoom(e.cName, 9);
				cookie.push(e.pName,e.cName);//把当前市的级别方式cookie
			}else if(e.url == "selectOneArea_QRate"){
				var make = markinfo(e.aName,e.cName,e.pName);
				cookie.push(e.pName,e.cName,e.aName); //把当前去放入cookie中
				 //区的时候
				lv = 4; //设置级别为4
				var markers = [];
				var thisq = [];
				thisq.push(e.aName);//八区放在数组里
				mapmake(thisq);
				
			    var myIcon1 = new BMap.Icon("/WSJC/resources/image/markers01.png", new BMap.Size(23, 25), {
		            // 指定定位位置
		            offset: new BMap.Size(10, 25),
		            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
		        });
			    var myIcon2 = new BMap.Icon("/WSJC/resources/image/markers02.png", new BMap.Size(23, 25), {
		            // 指定定位位置
		            offset: new BMap.Size(10, 25),
		        });
			    var myIcon3 = new BMap.Icon("/WSJC/resources/image/markers03.png", new BMap.Size(23, 25), {
		            // 指定定位位置
		            offset: new BMap.Size(10, 25),
		            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
		        });
			    var myIcon4 = new BMap.Icon("/WSJC/resources/image/markers04.png", new BMap.Size(23, 25), {
		            // 指定定位位置
		            offset: new BMap.Size(10, 25),
		            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
		        });
			    var p ;
			    var marker;
			    var io=[];
			    for(var k in make){
					p = new BMap.Point(make[k].gps_x,make[k].gps_y);
					if(make[k].test_result == 1){
						if(name == "mj_"){
							 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "xd_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "mjsb_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "atp_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "zw_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "bd_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}
						
					}else if(make[k].test_result == 2){
						 if(name == "mj_"){
							 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "xd_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "mjsb_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "atp_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "zw_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "bd_"){
				    		marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}
					}else if(make[k].test_result == "NaN"){
						 if(name == "mj_"){
							 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "xd_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "mjsb_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "atp_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "zw_"){
				    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
				    	}else if(name == "bd_"){
				    		marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"无","无",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
				    	}
					}else if(make[k].test_result == "noOpen"){
						 marker = new BMap.Marker(p ,{icon: myIcon4});  // 创建标注
						 io = [make[k].hospital_name,make[k].address,"未开通","未开通",null];    //点击标注展示里面的信息《a》标签也能写
					}
					
					var content = contents(io);  //传入IO
					//map.addOverlay(marker);              
					addClickHandler(content,marker); // 点击标注展示详细信息
//					markers.push(marker);
					map.addOverlay(marker); // 将标注添加 到地图中
				}
				var opts = {
						width : 200,     // 信息窗口宽度
						height: 130,     // 信息窗口高度
						title : "信息" , // 信息窗口标题
						//enableMessage:true//设置允许信息窗发送短息
					   };
				
				//执行上面定义那个点击事件
				function addClickHandler(content,marker){
					marker.addEventListener("click",function(e){
						openInfo(content,e)}
					);
				}
				
				//创建那个信息窗口
				function openInfo(content,e){
					var p = e.target;
					var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
					var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
					map.openInfoWindow(infoWindow,point); //开启信息窗口
				}
				map.centerAndZoom(e.aName, 13); 
				
			
			}else {
				var loadshow = [e.loadshow];
			}
	}
	var markers = [];
	map.addEventListener("click", csheng);//点击地图获取省市区
	function csheng(e){
		//点击地图获取省市区
		if(e.overlay){
			var pt = e.point;
			geoc.getLocation(pt, function(rs){
				var addComp = rs.addressComponents;
				//alert(addComp.province + ", " + addComp.city + ", " + addComp.district);//弹出省市区
				if(lv == 1){  //全国的时候
					//alert(addComp.province);
					var shi = getc(addComp.province); // 获得所有市   ，传入省
					map.centerAndZoom(addComp.province, 7);  //显示省下的所有市
					cookie.push(addComp.province);//把当前省的级别方式cookie
				}else if(lv == 2){  //省的时候
					var qu = getq(addComp.city,addComp.province);  // 获得所有区  ，传入市
					lv = 3;//设置级别为3
					map.centerAndZoom(addComp.city, 9);
					cookie.push(addComp.city);//把当前市的级别方式cookie
				}else if(lv == 3){ //区的时候
					var make = markinfo(addComp.district,addComp.city,addComp.province);  //传入区，和市，获取旗的数据
					cookie.push(addComp.district); //把当前去放入cookie中
					lv = 4; //设置级别为4
					var markers = [];
					var thisq = [];
					var thisqName = addComp.province+addComp.district
					thisq.push(thisqName);//八区放在数组里
					mapmake(thisq);
					
				    var myIcon1 = new BMap.Icon("/WSJC/resources/image/markers01.png", new BMap.Size(23, 25), {
			            // 指定定位位置
			            offset: new BMap.Size(10, 25),
			            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
			        });
				    var myIcon2 = new BMap.Icon("/WSJC/resources/image/markers02.png", new BMap.Size(23, 25), {
			            // 指定定位位置
			            offset: new BMap.Size(10, 25),
			        });
				    var myIcon3 = new BMap.Icon("/WSJC/resources/image/markers03.png", new BMap.Size(23, 25), {
			            // 指定定位位置
			            offset: new BMap.Size(10, 25),
			            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
			        });
				    var myIcon4 = new BMap.Icon("/WSJC/resources/image/markers04.png", new BMap.Size(23, 25), {
			            // 指定定位位置
			            offset: new BMap.Size(10, 25),
			            // 当需要从一幅较大的图片中截取某部分作为标注图标时，需要指定大图的偏移位置   
			        });
				    var p ;
				    var marker;
				    var io;
					for(var k in make){
						p = new BMap.Point(make[k].gps_x,make[k].gps_y);
						if(make[k].test_result == 1){
							if(name == "mj_"){
								 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "xd_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "mjsb_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "atp_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "zw_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "bd_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon1});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"合格",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}
							
						}else if(make[k].test_result == 2){
							 if(name == "mj_"){
								 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "xd_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "mjsb_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "atp_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "zw_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "bd_"){
					    		marker = new BMap.Marker(p,{icon: myIcon2});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,make[k].test_time,"不合格",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}
						}else if(make[k].test_result == "NaN"){
							 if(name == "mj_"){
								 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].s_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "xd_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].d_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "mjsb_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].sd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "atp_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].atp_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "zw_"){
					    		 marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].uv_id];    //点击标注展示里面的信息《a》标签也能写
					    	}else if(name == "bd_"){
					    		marker = new BMap.Marker(p,{icon: myIcon3});  // 创建标注
								 io = [make[k].hospital_name,make[k].address,"无","无",make[k].bd_id];    //点击标注展示里面的信息《a》标签也能写
					    	}
						}else if(make[k].test_result == "noOpen"){
							 marker = new BMap.Marker(p ,{icon: myIcon4});  // 创建标注
							 io = [make[k].hospital_name,make[k].address,"未开通","未开通",null];    //点击标注展示里面的信息《a》标签也能写
						}
						
						var content = contents(io);  //传入IO
						//map.addOverlay(marker);              
						addClickHandler(content,marker); // 点击标注展示详细信息
//						markers.push(marker);
						map.addOverlay(marker); // 将标注添加 到地图中
					}
					var opts = {
							width : 200,     // 信息窗口宽度
							height: 130,     // 信息窗口高度
							title : "信息" , // 信息窗口标题
							//enableMessage:true//设置允许信息窗发送短息
						   };
					
					//执行上面定义那个点击事件
					function addClickHandler(content,marker){
						marker.addEventListener("click",function(e){
							openInfo(content,e)}
						);
					}
					
					//创建那个信息窗口
					function openInfo(content,e){
						var p = e.target;
						var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
						var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象 
						map.openInfoWindow(infoWindow,point); //开启信息窗口
					}
					//map.centerAndZoom(thisqName, 13); 
					//map.setViewport(thisq);//thisq
					
				}
			});
		}else{
				var pt = e.point;
				geoc.getLocation(pt, function(rs){
				var addComp = rs.addressComponents;
				//alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
				$('#twinkle').text('');
				if(typeof(ProvinceName1) == "undefined" | ProvinceName1 =="" |ProvinceName1 == null |lv == 1){
					$('#twinkle').text("该区域超出了您的管辖范围!");
					twinkle();
				}else if(typeof(ProvinceName1) != "undefined" &&addComp.province != ProvinceName1  ){
					$('#twinkle').text("请返回上一级,查看此区域！");
					twinkle();
				}else if(addComp.province == ProvinceName1 && typeof(ProvinceName1) != "undefined"){
					$('#twinkle').text("请返回上一级,查看此区域！");
					twinkle();
				}
				})
		}
	}
	var ahref;
	//当IO传进来判断
    function contents(msg){
//alert(msg[0]);alert(msg[1]);alert(msg[2]);alert(msg[3]);alert(msg[4]);
    	if(msg[0]==null | msg[0]=="" | typeof(msg[0	])=="undefined"){  //有几个数据做几个判断
    		msg[0]="无数据";
    	}
    	if(msg[1]==null | msg[1]=="" | typeof(msg[1])=="undefined"){
    		msg[1]="无数据";
    	}
    	if(msg[2]==null | msg[2]=="" | typeof(msg[2])=="undefined"){
    		msg[2]="无数据";
    	}
    	if(msg[3]==null | msg[3]=="" | typeof(msg[3])=="undefined"){
    		msg[3]="无数据";
    	}
    	if(msg[4]==null| msg[4]=="" | typeof(msg[4])=="undefined"){
    		ahref = '<span id="pdfchakan" style="font-size:12px;float:right;">暂无详情'+'</span>';
    	}else{
    		ahref = '<a   href="'+e.base+'/country/user/to_PDF?TestID='+msg[4]+'" style="font-size:12px;float:right;" target="_blank">详情'+'</a>';
    	}
    	var br = '<br>';   // 定义换行符<br>
    	var Name = '<p style="font-size:12px;">名称：'+msg[0]+'</p>';
    	var Address = '<p style="font-size:12px;">地址：'+msg[1]+'</p>';
    	var testTime = '<p style="font-size:12px;">测试时间：'+msg[2]+'</p>';
    	var hegeType = '<span style="font-size:12px;">合格状态：'+msg[3]+'</span>';
    	var i = Name+Address+testTime+hegeType+ahref;
    	//var i = '名称：'+e[0]+br+'地址：'+e[1]+br+"测试时间："+e[2]+br+"合格状态:"+e[3]+br+a;  //把数据写到里面《a》标签在这里写
    	return i;
    }
    function getBoundary6(p,c,k,g){// p:覆盖区域的数组  c:颜色   K:透明度   g:边框线的粗细
		var bdary = new BMap.Boundary();
		bdary.get(p, function(rs){
			
			var count = rs.boundaries.length; 
			if (count === 0) {
				//alert('未能获取行政区域');
				//swal('未能获取行政区域!')
				return ;
			}
          	var pointArray = [];
			for (var i = 0; i < count; i++) {
				var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight:g, strokeColor: "#6600ff" ,fillOpacity:k,fillColor:c});
				map.addOverlay(ply);  //添加覆盖物
			}
			//map.centerAndZoom(addComp.province, 11);
		}); 
	}
    
    
    function getBoundary7(p,c,k,g){// p:覆盖区域的数组  c:颜色   K:透明度   g:边框线的粗细
		var bdary = new BMap.Boundary();
		bdary.get(p, function(rs){
			
			var count = rs.boundaries.length; 
			if (count === 0) {
				//alert('未能获取行政区域');
				//swal('未能获取行政区域!')
				return ;
			}
          	var pointArray = [];
			for (var i = 0; i < count; i++) {
				var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight:g, strokeColor: "#6600ff" ,fillOpacity:k,fillColor:c});
				map.addOverlay(ply);  //添加覆盖物
				map.setViewport(ply.getPath());    //调整视野     
			}   
			//map.centerAndZoom(addComp.province, 11);
		}); 
	}
    
    
  //画覆盖物
    function mapcolors6(q){
		map.clearOverlays();
		var k = "0.5";
		var colormap = "#D2691E";
		for(var num = 0;num < q.length; num++){
			getBoundary6(q[num],colormap,k,2);
		}
	}
    
    //旗那步画覆盖物
    function mapmake(q){
		map.clearOverlays();
		var k = "0.01";
		var colormap = "#D2691E"
		for(var num = 0;num < q.length; num++){
			getBoundary7(q[num],colormap,k,3);
		}
	}

    //右上角的那个控件
	/*var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); 
	map.addControl(top_right_navigation);*/
	

	// 获取省名字数组
	function getp(){
		CSName="";hegeNumber="";notHegeNumber="";eligibility="";
		var url = "";
		var testNAME = e.name ;
		if(e.getpUrl == null | e.getpUrl == "" | typeof(e.getpUrl) == "undefined"){
			url = "/country/user/chinaMapShow";
		}else{
			url = e.getpUrl;
		}
		$.ajax({
			url : e.base+url,
			cache: true,
            type: "POST",
            data: "testName="+e.name,
            async: false,
            error: function(request) {
            	$('#twinkle').text("请返回上一级");
				twinkle();
            },
            success: function(data){
            	
            	CSName = data.name;
            	hegeNumber = data.hege_num;										
            	notHegeNumber = data.number;
            	eligibility = data.hegelv+'%';
            	total = data.total;
            	other_num = data.other_num;
            	
            	var url = data.url;
            	$("#mapUrl").val(url);
            	var data1 = eval(data.list);
            	var str = JSON.stringify(data);
            	//alert(str);
            	//console.log(str);
            	var k = "0.5";
            	var name ;
            	var colormap ;
            	for(var i in data1){
            		if(data1[i].province_name == '宁夏回族自治区'){
            			name = "宁夏";
            		}else{
            			name = data1[i].province_name;
            		}
            		colormap = data1[i].color;
            		getBoundary6(name,colormap,k,2);
            	}
            	
            }
		});
		tools();
	}   

	//市名字
	
	function getc(pname){
		CSName="";hegeNumber="";notHegeNumber="";eligibility="";
		var name = e.name;
		var url = "";
		if(e.getcUrl == null | e.getcUrl == "" | typeof(e.getcUrl) == "undefined"){
			url = "/country/user/ProvinceMapShow";
		}else{
			url = e.getcUrl;
		}
		$.ajax({
			url : e.base+url,
			cache: true,
            type: "POST",
            data: {"province_name":pname,"testName":e.name},
            async: false,
            error: function(request) {
            	$('#twinkle').text("该名称与数据库不匹配");
				twinkle();
            },
            success: function(data) {
            	//var str = JSON.stringify(data);
            	//alert(str);
            	CSName = data.name;
    			hegeNumber = data.hege_num;										
            	notHegeNumber = data.number;
            	eligibility = data.hegelv+'%';
            	total = data.total;
            	other_num = data.other_num;
            	
            	var url = data.url;
            	var provinceName = data.province_name;
            	ProvinceName1 = provinceName;
            	$("#mapUrl").val(url);
            	$('#pName').val(provinceName);
            	var data1 = eval(data.list);			
            	var flag = data.is_municipal;
            	var k = "0.5";
            	var name ;
            	var colormap ;
            	map.clearOverlays(); 
            	for(var i in data1){
            		if(flag == "yes"){
            			name = data1[i].area_name;
            			colormap = data1[i].color;
                		getBoundary6(name,colormap,k,2);
                		lv = 3;
                		
            		}else{
            			name = data1[i].city_name;
                		colormap = data1[i].color;
                		getBoundary6(name,colormap,k,2);
                		lv = 2 ;
            		}
            	}
            	map.centerAndZoom(pname, 11);
            }
		});
		tools();
	}
	
	
	function getq(cname,pname){
		CSName="";hegeNumber="";notHegeNumber="";eligibility="";
		var name = e.name;
		var url = "";
		if(e.getqUrl == null | e.getqUrl == "" | typeof(e.getqUrl) == "undefined"){
			url = "/country/user/CityMapShow";
		}else{
			url = e.getqUrl;
		}
		$.ajax({
			url : e.base+url,
			cache: true,
            type: "POST",
            data: {"city_name":cname ,"testName": e.name,"province_name":pname},
            async: false,
            error: function(request) {
            },
            success: function(data) {
            	var url = data.url;
            	var provinceName = data.province_name;
            	var cityName = data.city_name;
            	$("#mapUrl").val(url);
            	$('#pName').val(provinceName);
            	$('#cName').val(cityName);
            	//var str = JSON.stringify(data);
            	//alert(str);
            	CSName = data.name;
    			hegeNumber = data.hege_num;										
            	notHegeNumber = data.number;
            	eligibility = data.hegelv+'%';
            	total = data.total;
            	other_num = data.other_num;
            	
            	var data1 = eval(data.list);
            	var k = "0.5";
            	var name ;
            	var colormap ;
            	map.clearOverlays(); 
            	for(var i in data1){
            		name = data1[i].area_name;
        			colormap = data1[i].color;
            		getBoundary6(name,colormap,k,2);
            	}
            }
		});
		tools();
	}
	
	//获取区下面的所有数据，都放在mark里面
	function markinfo(aname,cname,pname){
		CSName="";hegeNumber="";notHegeNumber="";eligibility="";
		var mark = [];
		var name = e.name ;
		var url = "";
		if(e.markinfoUrl == null | e.markinfoUrl == "" | typeof(e.markinfoUrl) == "undefined"){
			return false;
		}else{
			url = e.markinfoUrl;
		}
		$.ajax({
			url : e.base+url,
			cache: true,
            type: "POST",
            data: {
            	"area_name":aname,
            	"city_name":cname,
            	"province_name":pname,
            	"testName":e.name
            },
            async: false,
            error: function(request) {
            	swal("异常了");
            },
            success: function(data) {
            	var url = data.url;
            	var provinceName = data.province_name;
            	var cityName = data.city_name;
            	var areaName = data.name;
            	$('#mapUrl').val(url);
            	$('#pName').val(provinceName);
            	$('#cName').val(cityName);
            	$('#aName').val(areaName);
            	//var str = JSON.stringify(data);
            	//alert(str);
            	CSName = data.name;
    			hegeNumber = data.hege_num;										
            	notHegeNumber = data.number;
            	eligibility = data.hegelv+'%';
            	total = data.total;
            	other_num = data.other_num;
            	
            	var data = eval(data.list);
            	
            	map.clearOverlays(); 
            	for(var i in data){
            		mark.push(data[i]);
            	}
            }
		});
		tools();
		return mark;
	}
	
	//自定义控件（1）
	function ZoomControl(){
		  // 默认停靠位置和偏移量
		this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
		this.defaultOffset = new BMap.Size(10, 10);
	}
	ZoomControl.prototype = new BMap.Control();
	
	ZoomControl.prototype.initialize = function(map){
		  // 创建一个DOM元素
		  var div = document.createElement("div");
		  // 添加文字说明
		  //div.appendChild(document.createTextNode("返回上一级"));
		  // 设置样式
		  div.style.width = "72px";
		  div.style.height = "30px";
		  div.style.backgroundImage = "url("+e.base+"/resources/image/fanhui.png)";
		  div.style.cursor = "pointer";
		  div.style.border = "1px solid gray";
		  div.style.borderRadius = "6px";
		  div.style.padding = "10px";
		  div.style.backgroundColor = "white";
		  
		  // 绑定事件,点击一次放大两级
		  div.onclick = function(e){
			 // alert(lv);
			if(lv == loocked){  //lv == 1
				//alert("不能返回了！");
				$('#twinkle').text("这已经是您最高的视差范围，不能再返回了！");
				twinkle();
				//swal('')
				return false;
			}else if(lv == 3 && cookie[cookie.length-1] == "北京市"){
				lv = lv - 2;
				goback2(lv,cookie);
			}else if(lv == 4 && cookie[cookie.length-2] == "北京市"){
				goback2(lv,cookie);
			}
			else if(lv == 3 &&  cookie[cookie.length-1] == "天津市"){
				lv = lv - 2;
				goback2(lv,cookie);
			}else if(lv == 4 && cookie[cookie.length-2] == "天津市"){
				goback2(lv,cookie);
			}
			else if(lv == 3 &&  cookie[cookie.length-1] == "重庆市"){
				lv = lv - 2;
				goback2(lv,cookie);
			}else if(lv == 4 && cookie[cookie.length-2] == "重庆市"){
				goback2(lv,cookie);
			}
			else if(lv == 3 &&  cookie[cookie.length-1] == "上海市"){
				lv = lv - 2;
				goback2(lv,cookie);
			}else if(lv == 4 && cookie[cookie.length-2] == "上海市"){
				goback2(lv,cookie);
			}
			else{ 
				lv--;
				goback(lv,cookie);
			}
		  }
		  
		  // 添加DOM元素到地图中
		  map.getContainer().appendChild(div);
		  // 将DOM元素返回
		  return div;
		}
	  
		
	//自定义控件(2)
    function staticControl(){
        this.defaultAnchor = BMAP_ANCHOR_BOTTOM_RIGHT;
        this.defaultOffset = new BMap.Size(0,0);
    }
    //继承Control的API
    staticControl.prototype = new BMap.Control();
    //初始化控件
    staticControl.prototype.initialize=function(map){
       
       var div = document.createElement('div');
       div.style.width = "124px";
	   div.style.height = "247px";
	   div.style.backgroundImage = "url("+e.base+"/resources/image/myMap.png)";
	   div.style.border = "1px solid gray";   
	   div.style.backgroundColor = "white";  
        //添加DOM元素到地图中
        map.getContainer().appendChild(div);
        //返回DOM
        return div;
    }
    //创建控件实例
    var staticsCtrl = new staticControl();
    //添加到地图当中
    map.addControl(staticsCtrl);
	
    
    
    
  //自定义控件(3)------数据
    function staticRightControl(){
        this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
        this.defaultOffset = new BMap.Size(0,0);
    }
    //继承Control的API
    staticRightControl.prototype = new BMap.Control();
    //初始化控件
    staticRightControl.prototype.initialize=function(map){
       
       var div = document.createElement('div');
       div.style.width = "61px";
       div.style.cursor = "pointer";
	   div.style.height = "79px";
	   div.style.backgroundImage = "url("+e.base+"/resources/image/shuju.png)";
	   div.style.border = "1px solid gray";   
	   div.style.backgroundColor = "white";  
	   
	   div.onclick = function(e){
			  // window.parent
			   window.location.href= dataUrl; 
		   }
        //添加DOM元素到地图中
        map.getContainer().appendChild(div);
        //返回DOM
        return div;
    }
  //创建控件实例
    var staticsRightCtrl = new staticRightControl();
    //添加到地图当中
    map.addControl(staticsRightCtrl);
	
   
    
    
    
    
    
    
    //自定义控件(4)------统计
    function staticRightTowControl(){
        this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
        this.defaultOffset = new BMap.Size(63,0);
    }
    //继承Control的API
    staticRightTowControl.prototype = new BMap.Control();
    //初始化控件
    staticRightTowControl.prototype.initialize=function(map){
       
       var div = document.createElement('div');
       div.style.width = "61px";
       div.style.cursor = "pointer";
	   div.style.height = "79px";
	   div.style.backgroundImage = "url("+e.base+"/resources/image/tongji.png)";
	   div.style.border = "1px solid gray";   
	   div.style.backgroundColor = "white";  
	   
	   div.onclick = function(e){
		  // window.parent
		   parent.location.href= tongjuUrl; 
	   }
        //添加DOM元素到地图中
        map.getContainer().appendChild(div);
        //返回DOM
        return div;
    }
  
    
    //创建控件实例
    var staticsRightTowCtrl = new staticRightTowControl();
    //添加到地图当中
    map.addControl(staticsRightTowCtrl);
    
  
    
    
    
    
    //自定义控件(5)------显示 名称、合格、不合格数量 、合格率
    function lianheControl(){
        this.defaultAnchor = BMAP_ANCHOR_BOTTOM_RIGHT;
        this.defaultOffset = new BMap.Size(124,0);
    }
    //继承Control的API
    lianheControl.prototype = new BMap.Control();
    //初始化控件
    lianheControl.prototype.initialize=function(map){
       
       var div = document.createElement('div');
       
       //添加文字说明
       var br = "<br>";
       if(CSName == "NaN"){
    	   CSName = "—"
       }
       if(hegeNumber == "NaN"){
    	   hegeNumber = "—"; 
       }
       if(notHegeNumber == "NaN"){
    	   notHegeNumber = "—"; 
       }
       if(eligibility == "NaN%"){
    	   eligibility = "—"; 
       }
       if(total == "NaN"){
    	   total = "—"; 
       }
       if(other_num == "NaN"){
    	   other_num = "—"; 
       }
       div.innerHTML="管辖区域名称："+CSName+br+"合格数量："+hegeNumber+br+"不合格数量："+notHegeNumber+br+"合格率："+eligibility+br+"总数："+total+br+"其他："+other_num;
       
       div.style.width = "140px";
	   div.style.height = "120px";
	   div.style.border = "1px solid gray";   
	   div.style.backgroundColor = "white"; 
	   div.style.fontSize = "10px";
	   
        //添加DOM元素到地图中
        map.getContainer().appendChild(div);
        //返回DOM
        return div;
    }
		
    
    function tools (){
			if(cookie[0] != null){
				//创建控件实例
			    var lianheCtrl = new lianheControl();
			    //添加到地图当中
			    map.addControl(lianheCtrl);
				// 创建控件
				var myZoomCtrl = new ZoomControl();
				// 添加到地图当中
				map.addControl(myZoomCtrl);
				//创建控件实例
			    var staticsCtrl = new staticControl();
			    //添加到地图当中
			    map.addControl(staticsCtrl);
			}
		}tools();
		
		
		
		//返回上一步(普通省)
		function goback(lvs,cookie){
			if(lvs == 1){
				if(cookie[0]=="中国"){
					map.clearOverlays();   
					getp([e.loadshow]);
				}else{
					map.clearOverlays();   
					getp([e.loadshow]);
				}
					map.centerAndZoom(cookie[cookie.length-1],5);
					cookie.pop();
			}else if(lvs == 2){
				if(cookie.length <= 2){
					map.clearOverlays();   
					getc([e.loadshow]);
				}else{
					getc(cookie[cookie.length-2]);
				}
					map.centerAndZoom(cookie[cookie.length-2],7);
					cookie.pop();
			}else if(lvs == 3){
				if(cookie.length <= 2){
					map.clearOverlays();   
					getq([e.loadshow]);
				}else{
					map.clearOverlays();   
					getq(cookie[cookie.length-2],cookie[cookie.length-3]);
				}	
					map.centerAndZoom(cookie[cookie.length-2],9);
					cookie.pop();
			}
			
		}
		
		//返回上一步(直辖市)
		function goback2(lvs,cookie){
			if(lvs == 1){
				if(cookie[0]=="中国"){
					map.clearOverlays();   
					getp();
				}else{
					map.clearOverlays();   
					getp([e.loadshow]);
				}
					map.centerAndZoom(cookie[cookie.length-1],5);
					cookie.pop();
			}else if(lvs == 3){
				if(cookie.length <= 2){
					map.clearOverlays();   
					getq(cookie[0],cookie[cookie.length-1]);
				}else{
					map.clearOverlays();   
					getq(cookie[0],cookie[cookie.length-1]);
				}
					map.centerAndZoom(cookie[cookie.length-1],11);
					cookie.pop();
			}else if(lvs == 4){
				lv = lvs -1;
				if(cookie.length <= 2){
					//alert(cookie[0]+cookie[cookie.length-2])
					map.clearOverlays();   
					getq(cookie[0],cookie[cookie.length-2]);
				}else{
					//alert(cookie[cookie.length-2]+cookie[cookie.length-1])
					map.clearOverlays();   
					getc(cookie[cookie.length-2]);
				}
					map.centerAndZoom(cookie[cookie.length-2],9);
					cookie.pop();
			}
		}
		
		//和上面那个if判断是一样的
		var checkTil = function(string){
			if(typeof(string) == "object" & string instanceof Array){
				if( string.length == 0 || string[0] == null){
					return false;
				}else{
					return true;
				}
			}else{
				if(string == null || string == "" || typeof(string) == "undefined"){
					return false;
				}else{
					return true;
				}
			}
		}
		function twinkle(){
			color();
		}			
		function color(){
			//alert(a);
			var text=document.getElementById("twinkle");
			if(a==0){
				text.style.display="block";
			}
	        if(text.style.color=="red"){
	            text.style.color="#eff3f8";
	        }
	        else{
	            text.style.color="red";
	        }if(a<7){
        	   setTimeout(function(){
        		  color(); 
        	   },300);
        	   //alert(a);
        	   a++;
	        }else if(a==7){
	        	a=0;
	        	text.style.color="red";
	        }
	    }
}	